#include "tim.h"

tim t;
int light = 1;

int main() {
    while(1){
        t.run();
    }
    return 0;
}

void tim::run() {
    // 获取更新之后的值
    get_state();
    get_time_state();

    if(t.time_state_current == 1){
        // 延迟10ms
        usleep(10000);
        return ;
    }
    if(t.time_state_current == 0 && t.time_state_last == 1){
        switch (t.state) {
            case STRIGHT:
                // 直行休眠1秒
                for (int i = 0; i < 200; i++) {
                    ros::param::get("light", light);
                    while (light == 0) {}
                    usleep(10000);
                }
                break;
            case LEFT:
                for (int i = 0; i < 200; i++) {
                    ros::param::get("light", light);
                    while (light == 0) {}
                    usleep(10000);
                }
                break;
            case 3:
                for (int i = 0; i < 100; i++) {
                    ros::param::get("light", light);
                    while (light == 0) {}
                    usleep(10000);
                }
                break;
        }
        t.set_time_state();
    }

}

tim::tim() {
    time_state_last = 1;
    time_state_current = 1;
    state = 7;
}

void tim::set_time_state() {

}

void tim::get_state() {
    state = 1;
}

void tim::get_time_state() {
    time_state_last = time_state_current;
    time_state_current = 1;
}
